'use strict';

exports.register = function (server, option, next) {
    const Sequelize = server.app.Sequelize;
    const sequelize = server.app.db;
    var dataBaseName = {
        sender:"ww77sender",
        receiver:"ww77receiver"
    }

    var dataBase = {
        [dataBaseName.sender]: sequelize.define(dataBaseName.sender, {
            sender_id: {
                type: Sequelize.INTEGER,
                primaryKey: true,
                autoIncrement: true
            },
            nickname: {
                type: Sequelize.STRING
            },
            imghead: {
                type: Sequelize.STRING
            },
            message: {
                type: Sequelize.STRING
            },
            keywords: {
                type: Sequelize.STRING
            }
        }, {       
            tableName:dataBaseName.sender,
            freezeTableName: true,
            underscoredAll: false,
        })
    };
    var dataFn = require('../server/wangwang')(dataBase, sequelize);

    server.route({
        method:['GET','POST'],
        path: '/ww77/sender/upLoadInfo',
        handler: function(request,reply){
            var options = request.payload||request.url.query;
            console.log(11111111111,options);

            //验证传入参数
            if(typeof options!='object' || typeof options.keywords=='undefined' || typeof options.nickname=='undefined'){
                // return reply(wrapper(null,4002));
            }else{
                // options.mixnick = decodeURIComponent(options.mixnick);//decodeURIComponent() 函数可对 encodeURIComponent() 函数编码的 URI 进行解码。
            }
            dataFn.sender.insert(options);
            reply(111111);


        }
    });
    var namespace='morefun';
    var dir='/wangwang77';
    var wantuFn=require('../server/wantuFn')(namespace,dir);
    server.route({
        method:['GET','POST'],
        path: '/ww77/sender/getImgHead',
        handler: function(request,reply){
            var options = request.payload||request.url.query;
            //验证传入参数
            if(typeof options!='object' || typeof options.keywords=='undefined' || typeof options.nickname=='undefined'){
                // return reply(wrapper(null,4002));
            }else{
                // options.mixnick = decodeURIComponent(options.mixnick);//decodeURIComponent() 函数可对 encodeURIComponent() 函数编码的 URI 进行解码。
            }
            var imghead = options.imghead|| 'http://vrbuy.image.alimmdn.com/hotwind/panos/K/thumb.jpg?t=1481541528148';
            var imgCdnUrl=wantuFn.getImgwtUrlByUrl(imghead);
            reply(111);
        }
    });
    return next();
};

exports.register.attributes = {
    name: 'route-wangwang'
};